package com.cbb.net;

import android.content.Context;
import android.text.TextUtils;

import com.android.volley.toolbox.NetworkImageView;
import com.cbb.admin.cbb.R;


/**
 * Created by jxk on 2018/03/05
 * Email:676585325@qq.com
 */

public class HttpLoad {

    public static void getImage(Context context, String url, int defaultRes, NetworkImageView imageView) {
        imageView.setDefaultImageResId(getDefaultImage(defaultRes));
        imageView.setErrorImageResId(getDefaultImage(defaultRes));
        if (!TextUtils.isEmpty(url) && !url.startsWith("http")) {
            url = ConstantXin.BASE_URL_XIN + url;
        }
        imageView.setImageUrl(url, HttpUtils.getInstance(context).getImageLoader());

        if (TextUtils.isEmpty(url)) {
            imageView.setImageResource(getDefaultImage(defaultRes));
            return;
        }
        imageView.setImageUrl(url, HttpUtils.getInstance(context).getImageLoader());
    }

    public static int getDefaultImage(int resId) {
        if (resId == -1) {
           // return R.mipmap.icon_default_image;
            return R.mipmap.icon_girl;
        } else {
            return resId;
        }
    }
/*    public static abstract class HomePagerModule{
        *//**
         * 新 获取首页轮播图
         *//*
        public static void getCarouselTheme(Context context, String tag, String type,
                                            ResponseCallback<ResponseCarousel> callback) {
            final HashMap<String, String> params = new HashMap<>();
            params.put("type",type);
            GsonRequest<ResponseCarousel> request = new GsonRequest<>(Request.Method.POST, Constant.GET_CAROUSEL,
                    ResponseCarousel.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }
    }

    // 用户相关模块
    public static abstract class UserModule {
        *//**
         * 用户注册
         *//*
        public static void register(Context context, String tag, String phone, String password,
                                    ResponseCallback<ResponseBase> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("phone", phone);
            params.put("password", password);
            GsonRequest<ResponseBase> request = new GsonRequest<ResponseBase>(Request.Method.POST, Constant.REGISTER,
                    ResponseBase.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

        *//**
         * 忘记密码
         *//*
        public static void forgetPsw(Context context, String tag, String phone, String password,
                                     ResponseCallback<ResponseBase> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("phone", phone);
            params.put("password", password);
            GsonRequest<ResponseBase> request = new GsonRequest<ResponseBase>(Request.Method.POST, Constant.REGISTER,
                    ResponseBase.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

        *//**
         * 获取验证码
         *//*
        public static void getMessageCode(Context context, String tag, String phone,
                                          ResponseCallback<ResponseBase> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("phone", phone);
            GsonRequest<ResponseBase> request = new GsonRequest<ResponseBase>(Request.Method.POST, Constant.REGISTER,
                    ResponseBase.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

        *//**
         * 用户登录
         *//*
        public static void login(Context context, String tag, String phone, String password,
                                 ResponseCallback<LoginResult> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("phone", phone);
            params.put("password", password);
            GsonRequest<LoginResult> request = new GsonRequest<LoginResult>(Request.Method.POST, Constant.LOGIN,
                    LoginResult.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

        *//**
         * 意见反馈
         *//*
        public static void feedBack(Context context, String tag, String content,
                                    ResponseCallback<ResponseBase> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("userid", Utils.getUserID(context) + "");
            params.put("phone", Utils.getUserPhone(context));
            params.put("content", content);
            params.put("tokenId", Utils.getTokenId(context));
            GsonRequest<ResponseBase> request = new GsonRequest<>(Request.Method.POST, Constant.ABOUT_US,
                    ResponseBase.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

        *//**
         * 关于我们
         *//*
        public static void aboutUs(Context context, String tag,
                                   ResponseCallback<ResonseAboutUs> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("tokenId", Utils.getTokenId(context));
            GsonRequest<ResonseAboutUs> request = new GsonRequest<>(Request.Method.POST, Constant.ABOUT_US,
                    ResonseAboutUs.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }
        *//**
         * 修改个人信息
         *//*
        public static void modifyMineInfo (Context context, String tag, String id_photo_url, String phone,
                                           String realname, String id_card,
                                           ResponseCallback<LoginResult> callback) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("userid", Utils.getUserID(context) + "");
            params.put("id_photo_url", id_photo_url);
            params.put("phone", phone);
            params.put("realname", realname);
            params.put("id_card", id_card);

            Log.v("图片",id_photo_url);
            GsonRequest<LoginResult> request = new GsonRequest<LoginResult>(Request.Method.POST, Constant.MODIFY_INFO,
                    LoginResult.class, null, params, callback, callback);
            HttpUtils.getInstance(context).request(tag, request);
        }

    }*/
}
